
import java.util.*;

class Memento {

    private String state;
    private String date;
    private String people;
    private String mood;
    private String place;

    public Memento(String state, String date, String people, String mood, String place) {
        this.date = date;
        this.mood = mood;
        this.people = people;
        this.place = place;
        this.state = state;
    }

    public String getSavedState() {
        return state;
    }

    public String getSavedDate() {
        return date;
    }

    public String getSavedMood() {
        return mood;
    }

    public String getSavedPeople() {
        return people;
    }

    public String getSavedPlace() {
        return place;
    }

}

class TimeStamp {

    private String state;
    private String date;
    private String people;
    private String mood;
    private String place;

    public TimeStamp(String date, String people, String mood, String place) {
        this.date = date;
        this.mood = mood;
        this.people = people;
        this.place = place;
    }

    public void set(String state, String date, String people, String mood, String place) {
        System.out.println("Setting state to " + state);
        this.state = state;
        this.date = date;
        this.mood = mood;
        this.people = people;
        this.place = place;
    }

    public Memento save() {
        System.out.println("Saving to Memento.");
        return new Memento(state, date, people, mood, place);
    }

    public void restore(Memento m) {
        state = m.getSavedState();
        date = m.getSavedDate();
        mood = m.getSavedMood();
        people = m.getSavedPeople();
        place = m.getSavedPlace();
        System.out.println("Restored State: " + state + " Date: " + date + " Mood: " + mood + " People: " + people + " Place: " + place);
    }
}

class TimeMachine {

    private ArrayList<Memento> savedStates = new ArrayList<Memento>();
    
    public void addMemento(Memento m) {        
        savedStates.add(m);
    }

    public Memento getMemento(int index) {
        return savedStates.get(index);
    }
}

class Task5 {

    public static void main(String[] args) {
        TimeMachine caretaker = new TimeMachine();
        TimeStamp originator = new TimeStamp("01.01.1990", "Kazakh", "Good", "Kazakhstan");
        originator.set("State1", "01.01.1889", "Russian", "Bad", "Russia");
        originator.set("State2", "01.01.2000", "Indian", "Fine", "India");
        caretaker.addMemento(originator.save());
        originator.set("State3", "01.01.2111", "Georgian", "Good", "Georgia");
        caretaker.addMemento(originator.save());
        originator.set("State4", "03.02.1990", "Japanese", "Good", "Japan");
        originator.restore(caretaker.getMemento(0));
    }
}
